package com.woniuxy.stage3demo.controller.kang;

import com.github.pagehelper.PageInfo;
import com.woniuxy.stage3demo.bean.ResultMsg;
import com.woniuxy.stage3demo.bean.kang.FraudEngineBean;
import com.woniuxy.stage3demo.pageHelper.PageRequest;
import com.woniuxy.stage3demo.pageHelper.TableResult;
import com.woniuxy.stage3demo.service.kang.IFraudEngineService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/fraud")
public class FraudController {

    @Resource
    private IFraudEngineService fraudEngineServiceImpl;

    @GetMapping(value = "/findLimit",produces = {"application/json;charset=utf-8"})
    public ResultMsg findLimit(PageRequest pageRequest, FraudEngineBean fraudEngineBean){

//        System.out.println(pageRequest+"````"+fraudEngineBean);

        PageInfo<FraudEngineBean> fraud = fraudEngineServiceImpl.findLimit(pageRequest, fraudEngineBean);

//        System.out.println(fraud.getList());

        return new ResultMsg(200,"成功",new TableResult(fraud.getTotal(),fraud.getList()));
    }

    @PutMapping(value = "/statusChange/{id}/{us}",produces = {"application/json;charset=utf-8"})
    public ResultMsg statusChange(@PathVariable("id") Long id,@PathVariable("us") int us){
        FraudEngineBean fraudEngineBean = new FraudEngineBean();
        fraudEngineBean.setId(id);
        fraudEngineBean.setUseStatus(us);

        System.out.println(fraudEngineBean);

        fraudEngineServiceImpl.modFraudEngine(fraudEngineBean);

        return new ResultMsg(200,"成功",null);
    }

    @DeleteMapping(value = "/{id}",produces = {"application/json;charset=utf-8"})
    public ResultMsg delFraud(@PathVariable("id") Long id){

        fraudEngineServiceImpl.delFraudEngine(id);
        return new ResultMsg(200,"成功",null);
    }

    @PostMapping(value = "/addFraud",produces = {"application/json;charset=utf-8"})
    public ResultMsg addFraud(@RequestBody FraudEngineBean fraudEngineBean){
//        System.out.println(fraudEngineBean);

        fraudEngineServiceImpl.addFraudEngine(fraudEngineBean);

        return new ResultMsg(200,"成功",null);
    }

    @PutMapping(value = "/modFraud",produces = {"application/json;charset=utf-8"})
    public ResultMsg modFraud(@RequestBody FraudEngineBean fraudEngineBean){
        System.out.println(fraudEngineBean);

        fraudEngineServiceImpl.modFraudEngine(fraudEngineBean);

        return new ResultMsg(200,"成功",null);
    }

}
